package com.usian.skill.controller;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import com.usian.skill.common.Result;
import com.usian.skill.service.SkillUserService;
import com.usian.skill.vo.LoginVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/login")
public class LoginController {

	private static Logger log = LoggerFactory.getLogger(LoginController.class);
	
	@Autowired
    SkillUserService userService;
	
	/*@Autowired
	RedisService redisService;*/
	
    @RequestMapping("/to_login")
    public String toLogin() {
        return "login";
    }
    @ResponseBody
    @RequestMapping("/do_login")
    public Result<String> doLogin(LoginVo loginVo, HttpSession session) {
        Result login = userService.login(loginVo);
        if(login.getCode()==0){
            String data = (String)login.getData();
            session.setAttribute("userId",data);
        }
        return login;
    }
}
